<template>
	<view>
		<image style="width: 100%;" :src="src" mode="widthFix" @click="saveImgToLocal"></image>
		<view style="width:100%;text-align: center;height: 90upx;line-height: 90upx;color: #333;position: fixed;bottom: 10upx; left: 0;" @click="openSetting" >
			<!-- <button
				style="
				margin: 0;padding: 0;border: 1px solid transparent;outline: none;background: transprant;
				width: 300upx;height: 90upx;line-height: 90upx;color: #fff;display: inline-block;"
				open-type="openSetting" bindopensetting="callback"
			></button> -->
			图片保存不了?来这里设置
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				src:'',
			}
		},
		onLoad:function(){
			uni.showLoading()
			uni.getStorage({
				key: 'user_id',
				success: (res) => {
					this.user_id = res.data
					this.setAjax()
				},
				fail: () => {
					uni.navigateTo({
						url: '../../pages/login/login'
					});
				}
			});
		},
		methods:{
			setAjax(){
				uni.request({
					url: 'https://cx.mingmeijt.com/Api/QShare/shareUser',
					method: 'POST',
					data: {
						user_id: this.user_id,
						session_id: uni.getStorageSync("sessionid"),
					},
					header:{
						'Content-Type':'application/x-www-form-urlencoded',
					},
					success: (res) => {
						if(res.data.code == 999){
							uni.navigateTo({
								url:'/pages/999/999'
							})
						};
						if(res.data.code == 998){
							uni.navigateTo({
								url:'/pages/login/login'
							})
						}
						this.src = 'https://cx.mingmeijt.com' + res.data.data
						
					}
				})
				uni.hideLoading()
			},
			saveImgToLocal(){
				let o = this
				uni.downloadFile({
						url: this.src,//图片地址
						success: (res) =>{
							var imgpath = res.tempFilePath;
							if (res.statusCode === 200){
								uni.saveImageToPhotosAlbum({
									filePath: imgpath,
									success: function(res) {
										uni.hideLoading();
										uni.showToast({
											title: '保存成功！'
										})
									},
									fail: function(res) {
										uni.hideLoading();
										uni.showToast({
											title: '保存失败！',
											icon: 'none'
										})
									}
								})
							}
								// if (res.statusCode === 200){
								// 		uni.saveImageToPhotosAlbum({
								// 				filePath: res.tempFilePath,
								// 				success: function() {
								// 						uni.showToast({
								// 								title: "保存成功",
								// 								icon: "none"
								// 						});
								// 				},
								// 				fail: function() {
								// 						uni.showToast({
								// 								title: "保存失败",
								// 								icon: "none"
								// 						});
								// 				}
								// 		});
								// } 
								setTimeout(function() {
									o.hide()
								}, 10);
						}
				})
			},
			openSetting () {
				uni.openSetting()
			},
			jump(e){
				uni.navigateTo({
					url: e.currentTarget.dataset.src
				});
			},
		}
	}
</script>

<style>

</style>
